﻿<style>
    .tbl { padding: 10px; margin-top: 5px; }
    .tbl b { font-size: 20px; }
    .tbl span { color: red; font-size: 18px; margin-right: 50px; font-family: Arial; }
</style>
<div class="ld-tabs" id="tab_warehouse">
    <ul>
        <li class="k-state-active">收支汇总</li>
        <li>帐号流水</li>
    </ul>
    <div>
        <div class="k-block divToolbar">
            <div style="display: inline-block;">
                <b>客户类型：</b>
                <select id="ddlCtype">
                    <option value="0" selected="selected">全部</option>
                    <option value="1">顾客</option>
                    <option value="2">供应商</option>
                </select>
            </div>
            <div style="display: inline-block">
                <input type="text" id="txtCustomer" data-value="0" />
            </div>
            <input type="checkbox" id="cbZero" checked="checked" onchange="Filters()" />隐藏零余额
        </div>
        <div id="grid_payment_tops" style="text-align: center"></div>
        <div class="k-block tbl">
            <b>顾客总余额：</b><span id="spCustomer"></span>
            <b>供应商总余额：</b><span id="spSupplier"></span>
        </div>
    </div>
    <div>
        <div id="bankList">
            <ul>
                @foreach (var bank in (LuxDiner.Model.Financial.BankCollection)ViewBag.Banks)
                {
                    <li>@bank.ShowName</li>
                }
            </ul>
        </div>
    </div>
</div>

<script class="init">
    LocatedMenu("财务管理", "收支汇总");
    $("#ddlCtype").kendoDropDownList({
        change: function (e) {
            Filters();
        }
    });

    var allCustomer = Whale.Remote.GetEntity({
        url: "/Members/Customer/Gets",
        parameters: {
            customerStatus: 1
        }
    });
    $("#txtCustomer").kendoComboBox({
        placeholder: "请选择客户...",
        filter: "contains",
        dataTextField: "PinYinAndMobile",
        template: "#=ComplexName#",
        dataValueField: "ID",
        dataSource: allCustomer,
        change: function (e) {
            if ($.isNumeric(this.value())) {
                var item = this.dataItem();
                $("#txtCustomer").attr("data-value", item.ID);
                this.text(item.ComplexName);
            } else if(this.text()=="")
                $("#txtCustomer").attr("data-value", 0);
            Filters();
        }
    });

    $(function () {
        var totalBalance = Whale.Remote.GetResult({
            url: "/Financial/Payment/GetTotalBalance"
        });
        if (totalBalance != null && totalBalance.Success) {
            $("#spCustomer").html(kendo.toString(totalBalance.Data[0], "c"));
            $("#spSupplier").html(kendo.toString(totalBalance.Data[1], "c"));
        }
    });
</script>

<script class="grid_payment_tops_columns">
    var payTopsFields = [{
        title: "客户",
        field: "Customer.Corporation",
        width: 300
    }, {
        title: "姓名",
        field: "Customer.RealName",
        width: 100
    }, {
        title: "手机",
        field: "Customer.Mobile",
        width: 150
    }, {
        title: "客户类型",
        template: "#=ShowCustomerType(Customer.CType) #",
        width: 100
    }, {
        title: "余额",
        field: "Balance",
        format: "{0:c}",
        width: 100
    }, {}];

    function ShowCustomerType(ctype) {
        if (ctype == 1)
            return "顾客";
        else if (ctype == 2)
            return "供应商";
        else
            return "";
    }
</script>

<script type="text/x-kendo-template" id="detailsTemplate">
    <div class="grid_payments"></div>
</script>

<script class="detail_init">
    function detailInit(e) {
        var detailRow = e.detailRow;
        detailRow.find(".grid_payments").kendoGrid({
            columns: [{
                title: "单据号",
                field: "OrderNo",
                template: "#=GetOperations(OrderNo,Method)#",
                width: 130
            }, {
                title: "发生金额",
                field: "Money",
                format: "{0:c}",
                width: 100
            }, {
                title: "余额",
                field: "Balance",
                format: "{0:c}",
                width: 100
            }, {
                title: "备注",
                field: "Description",
                width: 200
            }, {
                title: "日期",
                template: "#=kendo.toString(kendo.parseDate(CreatedOn),'yyyy-MM-dd')#",
                width: 100
            }, {}],
            dataSource: Whale.dataSource({
                url: "/Financial/Payment/GetPayments",
                pageSize: 10,
                getParameters: function () {
                    return {
                        customerID: e.data.CustomerID

                    };
                }
            }),
            pageable: {
                messages: {
                    empty: "暂无数据"
                }
            },
            dataBound: function (e) {
                //让表头居中
                $("th.k-header").attr("style", "text-align:center; font-weight:bold;");
            },
        });
    }

    function GetOperations(orderNo, method) {
        var html = "";
        if (orderNo != null)
            html = "<a href=\"javascript:ShowOrder('" + orderNo + "'," + method + ")\">" + orderNo + "</a>";
        return html;
    }

    function ShowOrder(orderNo, method) {
        if (wndGeneralEdit != null && typeof wndGeneralEdit != "undefined") {
            wndGeneralEdit.setOptions({ title: "单据详情", width: 800 });
            var url = "/Orders/DealOrder/Order/";
            if (method == 21 || method == 22) {
                url = "/Orders/PaidOrder/Order/";
            }
            wndGeneralEdit.refresh({ url: url + orderNo });
            wndGeneralEdit.open();
        }
    }
</script>

<script class="grid_config">
    $(function () {
        $("#grid_payment_tops").kendoGrid({
            columns: payTopsFields,
            dataSource: Whale.dataSource({
                url: "/Financial/Payment/GetTops",
                getParameters: function () {
                    return {
                        customerID: $("#txtCustomer").attr("data-value"),
                        getCustomer: true,
                        hideZero: $("#cbZero").is(":checked"),
                        customerType: $("#ddlCtype").data("kendoDropDownList").value()
                    };
                },
                pageSize: 20

            }),
            pageable: {
                messages: {
                    empty: "暂无数据"
                }
            },
            dataBound: function (e) {
                //让表头居中
                $("th.k-header").attr("style", "text-align:center; font-weight:bold;");
            },
            detailTemplate: kendo.template($("#detailsTemplate").html()),
            detailInit: detailInit
        });
    });

    function Filters() {
        $("#grid_payment_tops").data("kendoGrid").dataSource.page(0);
        $("#grid_payment_tops").data("kendoGrid").dataSource.read();
    }



</script>

<script class="banks">
    $("#bankList").kendoTabStrip({
        contentUrls: [
            @foreach (var bank in (LuxDiner.Model.Financial.BankCollection)ViewBag.Banks)
            {
                <text>'/Financial/Payment/VBankWater/@bank.ID',</text>
            }
        ]
    }).data("kendoTabStrip").select(0);
</script>

